<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <title>跨界营销平台</title>
    <meta name="keywords" content="跨界营销平台">
    <meta name="description" content="跨界营销平台">
    <link href="/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}" rel="stylesheet">
    <link href="/css/font-awesome.css?v=4.4.0"  th:href="@{/css/font-awesome.css?v=4.4.0}" rel="stylesheet">
    <link href="/css/animate.css"  th:href="@{/css/animate.css}" rel="stylesheet">
    <link href="/css/style.css"  th:href="@{/css/style.css}" rel="stylesheet">
    <link href="/css/login.css"  th:href="@{/css/login.css}" rel="stylesheet">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html"/>
    <![endif]-->
    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>

</head>

<body class="signin">
<div class="signinpanel">
    <div class="row">
        <div class="col-sm-7">
            <div class="signin-info">
                <div class="logopanel m-b">
                    <h1>天源华云</h1>
                </div>
                <div class="m-b"></div>
                <h3>
                    欢迎使用 <strong>跨界营销后台管理系统</strong>
                </h3>
                <ul class="m-b">
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 优惠券发布审核</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 统计报表</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 门店管理</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> 广告审核</li>
                    <li><i class="fa fa-arrow-circle-o-right m-r-xs"></i> ......</li>
                </ul>
            </div>
        </div>
        <div class="col-sm-5">
            <form id="signupForm">
                <h3 class="text-center">用户登录</h3>
                <p class="m-t-md text-center">欢迎登录跨界营销后台管理系统</p>
                <input type="text" name="username"  id="username" class="form-control uname"
                       th:value="${username}"/>
                <input type="password" name="password" id="password"
                       class="form-control pword m-b" th:value="${password}"/>
                <a id="login" class="btn btn-login btn-block">登录</a>
                <!--按钮模块-->
                <div class="outside-login" style="display: none">
                    <div class="outside-login-tit">
                        <span>链接</span>
                    </div>
                    <div class="outside-login-cot">
                        <a class="outside-login-btn wxoa actived oschina J-btnSwitchLoginType" target="_Blank"
                           href="https://www.oschina.net/p/bootdo">
                            <em><i class="fa fa-home"></i></em>
                            <span>oschina主页</span>
                        </a>
                        <a class="outside-login-btn wxoa actived my J-btnSwitchLoginType" target="_Blank"
                           href="https://gitee.com/lcg0124/bootdo">
                            <em><i class="fa fa-git-square"></i></em>
                            <span>码云仓库</span>
                        </a>
                        <a class="outside-login-btn wxoa actived git J-btnSwitchLoginType" target="_Blank"
                           href="https://github.com/lcg0124/bootdo">
                            <em><i class="fa fa-github"></i></em>
                            <span>GitHub仓库</span>
                        </a>
                    </div>
                </div>

            </form>
        </div>
    </div>
    <!--     <div class="signup-footer"> -->
    <!--         <div class="pull-left" style="color: green;">&copy; 2018 All Rights Reserved. 哈尔滨天源华云        </div> -->
    <!--     </div> -->
</div>
<script th:inline="javascript"> var ctx = [[@{/}]] ; </script>
<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4" th:src="@{/js/jquery.min.js?v=2.1.4}"></script>
<script src="/js/bootstrap.min.js?v=3.3.6" th:src="@{/js/bootstrap.min.js?v=3.3.6}"></script>

<!-- 自定义js -->
<script src="/js/content.js?v=1.0.0" th:src="@{/js/content.js?v=1.0.0}"></script>

<!-- jQuery Validation plugin javascript-->
<script src="/js/ajax-util.js"  th:src="@{/js/ajax-util.js}"></script>
<script src="/js/plugins/validate/jquery.validate.min.js" th:src="@{/js/plugins/validate/jquery.validate.min.js}"></script>
<script src="/js/plugins/validate/messages_zh.min.js" th:src="@{/js/plugins/validate/messages_zh.min.js}"></script>
<script src="/js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script src="/js/crypto-js.min.js"  th:src="@{/js/crypto-js.min.js}"></script>
<script type="text/javascript">
    var secret;

    $(document).ready(function () {
        $("#login").on('click',function(){$("#signupForm").submit();});
        validateRule();
        $("body").keydown(keyDownLogon);
    });

    $.validator.setDefaults({
        submitHandler: function () {
            login();
        }
    });

    function login() {
        getKey();
        var pwd = encrypt($("#password").val());
        $.ajax({
            type: "POST",
            url: ctx+"login",
            data: {
                username : $("#username").val(),
                password : pwd
            },
            success: function (r) {
                if (r.code == 0) {
                    var index = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    parent.location.href = ctx+'index';
                } else {
                    layer.msg(r.msg);
                }
            },
        });
    }

    function getKey(){
        $.ajax({
            type: "GET",
            url: ctx+"wxs/getKey",
            async: false,
            success: function (r) {
                secret = r;
            }
        });
    }

    /**
     * 加密（需要先加载lib/aes/aes.min.js文件）
     * @param word
     * @returns {*}
     */
    function encrypt(word){
        var key = CryptoJS.enc.Utf8.parse(secret);
        var srcs = CryptoJS.enc.Utf8.parse(word);
        var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
        return encrypted.toString();
    }

    function keyDownLogon(){
        if (event.keyCode == "13") {
            $("#login").trigger('click');
        }
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                username: {
                    required: true
                },
                password: {
                    required: true
                }
            },
            messages: {
                username: {
                    required: icon + "请输入您的用户名",
                },
                password: {
                    required: icon + "请输入您的密码",
                }
            }
        })
    }
</script>
</body>
</html>
